package com.plugin.dingding;

import jdk.nashorn.internal.runtime.logging.Logger;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/ding")
@CrossOrigin
@Log4j2
public class ApiController {

    @GetMapping("/index")
    public AjaxRet index(){
        return AjaxRet.success(1);
    }

    @PostMapping("/getDingUserByCode")
    public AjaxRet getOpenidByCode(String code){
        log.info("code::"+code);
        try{
            Map<String, Object> map = ZWDingUtil.getDingUserByCode(code);
            return AjaxRet.success(map);
        }catch (Exception e){
            return AjaxRet.error(e.getMessage());
        }
    }

    @GetMapping("/getDingUserByCode")
    public AjaxRet getOpenidByCode_Get(String code){
        log.info("code::"+code);
        try{
            Map<String, Object> map = ZWDingUtil.getDingUserByCode(code);
            return AjaxRet.success(map);
        }catch (Exception e){
            return AjaxRet.error(e.getMessage());
        }
    }

    @PostMapping("/getDingUserByCodeTesting")
    public AjaxRet getOpenidByCodeTesting(String code){
        log.info("code::"+code);
        Map<String,Object> mapdata = new HashMap<String,Object>();
        mapdata.put("openid",code+"openid");
        mapdata.put("tenantId", code+"tenantId");
        mapdata.put("accountId", code+"accountId");
        mapdata.put("tenantName", "张三");
        mapdata.put("lastName","zhangsan");
        mapdata.put("nickNameCn", "zhangsan");
        return AjaxRet.success(mapdata);
    }



}
